<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/layui/css/layui.css">
    <script src="/js/libs/jquery-2.1.1.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-select.min.css">
    <script src="/js/bootstrap/bootstrap.min.js"></script>
    <script src="/js/bootstrap/bootstrap-select.min.js"></script>
    <script src="/js/jq.js"></script>
    <script src="/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/layui/layui.js"></script>
    <script src="/js/dict.js"></script>
    <script src="/js/libs/jquery.ztree.all-3.5.min.js"></script>
    <script src="/js/my/ztree-menu.js"></script>
    <script src="/js/my/permission.js"></script>
    <script src="/js/plugin/datatables/jquery.dataTables.min.js"></script>
    <script src="/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
</head>
<body>
<div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div>
            <header style="height: 100%">
                <div align="left">
                    <table style="width: 100%">
                        <tr>
                            <td>
                                <form class="form-inline" onsubmit="return false">
                                    <div class="form-group">
                                        供应商名称：
                                        <input id="name" name="name" type="text" class="form-control" placeholder="供应商名称">
                                        联系人：
                                        <input id="contact" name="contact" type="text" class="form-control" placeholder="联系人">
                                    </div>
                                </form>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <button id="searchBt" class="layui-btn layui-btn-sm search"><i class="layui-icon">&#xe615;</i>搜索</button>
                            </td>
                            <td align="right">
                                <button class="layui-btn layui-btn-sm" permission="fas:supplier:add"  onclick="openIFrame('addSupplier.html','添加供应商')">
                                    <i class="layui-icon">&#xe608;</i> 添加
                                </button>
                            </td>
                        </tr>

                    </table>
                </div>
            </header>

            <div>
                <div class="widget-body no-padding">
                    <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                        <thead>
                            <tr>
                            </tr>
                            <tr>
                                <th>id</th>
								<th>供应商名称</th>
								<th>联系人</th>
								<th>联系电话</th>
								<th>联系地址</th>
								<th>创建时间</th>
								<th>创建人</th>
								<th>修改人</th>
                                <th>是否可用</th>
                                <th>备注</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

<script type="text/javascript" src="/js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="/js/jq.js"></script>
<script type="text/javascript" src="/js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript" src="/js/my/permission.js"></script>
<script type="text/javascript">
var pers = checkPermission();

var example;
function init(){
	example = 
    	$('#dt-table').DataTable({
        	"searching": false,
        	"processing": false,
        	"serverSide" : true,
        	"language": {
                "url": "/js/plugin/datatables/Chinese.lang"
            },
        	"ajax": {
        		"url" : "/supplier/list",
        		"type":"get",
        		"data":function(d){
    				d.name = $("#name").val().trim();
    				d.contact = $("#contact").val().trim();
    			}
        	},
        	"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",	
            "columns": [
                {"data" : "id", "defaultContent" : "", "visible": false},
				{"data" : "name", "defaultContent" : ""},
				{"data" : "contact", "defaultContent" : ""},
				{"data" : "phone", "defaultContent" : ""},
				{"data" : "address", "defaultContent" : ""},
				{"data" : "createTime", "defaultContent" : ""},
				{"data" : "createName", "defaultContent" : ""},
				{"data" : "updateName", "defaultContent" : ""},
                {
                    "data" : "usable",
                    "defaultContent" : "",
                    "render": function (data, type, row) {
                        return getDict('boolean')[data];
                    }
                },
                {"data" : "remark", "defaultContent" : ""},
                {
                    "data": "",
                    "defaultContent": "",
                    "orderable":false,
                    "render": function (data, type, row) {
                       var id = row['id'];
                       var href = "updateSupplier.html?id=" + id;
                       var edit = buttonEdit(href, "fas:supplier:add", pers);
                       var del = buttonDel(id, "fas:supplier:del", pers);
                       return edit + del;
                    }
                },
                
            ],
            "order": [[ 0, "asc" ]],
            "createdRow": function ( row, data, index ) {
                $(row).bind({
                    click: function () {
                        if ($(this).hasClass('success') ) {
                            $(this).removeClass('success');
                        } else {
                            example.$('tr.success').removeClass('success');
                            $(this).addClass('success');
                        }
                    },
                    dblclick: function () {
                        if ($.inArray("fas:supplier:edit", pers) >= 0) {
                            var id = data.id;
                            openIFrame("updateSupplier.html?id=" + id);
                        }
                    }
                });
            }
        } );
}

layui.use('layer', function(){
    var layer = layui.layer;
});

function del(id){
	layer.confirm('确定要删除吗？', {
        btn : [ '确定', '取消' ]
    }, function() {
    	$.ajax({
            type : 'delete',
            url : '/supplier/'+id,
            success : function(data) {
                example.ajax.reload();
                layer.msg("删除成功");
            }
        });
        
        layer.close(1);
    });
}

$("#searchBt").click(function(){
	example.ajax.reload();
});

init();
</script>
